from django.contrib.auth.models import Permission, Group,ContentType

from rest_framework.generics import ListAPIView
from rest_framework.viewsets import ModelViewSet

from apps.meiduo_admin.serializers.permission import PermissionSerializer, GroupSerializer, ContentTypeSerializer, \
    AdminSerializer
from apps.users.models import User


# 这是权限的视图
class PermissionView(ModelViewSet):
    queryset = Permission.objects.all()
    serializer_class = PermissionSerializer
# 这是权限类型的视图
class ContentTypeView(ListAPIView):
    queryset = ContentType.objects.all().order_by('id')
    serializer_class = ContentTypeSerializer
    pagination_class = None
# 这是用户组的视图
class GroupView(ModelViewSet):
    queryset = Group.objects.all()
    serializer_class = GroupSerializer

# 这是简单实现用户权限的显示
class SimplePermissionView(ListAPIView):
    queryset = Permission.objects.all().order_by('id')
    serializer_class = PermissionSerializer
    pagination_class = None

# 这是用户管理员的增删改查
class AdminView(ModelViewSet):
    queryset = User.objects.filter(is_staff=True).order_by('id')
    serializer_class = AdminSerializer



# 这是管理员的显示
class AdminListAPIView(ListAPIView):
    queryset = Group.objects.all()
    serializer_class = GroupSerializer
    pagination_class =  None
